<?php
/**
* @myIPN for sobi 2
* @Copyright (C) 2007 Ethan Chai Voon Chong, http://www.ethansoft.com
* @All Rights Reserved
*/

defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );

class HTML_output {

	function listEntries( &$rows, $search, $pageNav ) {
		global $my, $database;
		?>
		<form action="index2.php" method="post" name="adminForm">
		<table>
		<tr align=right>
		<td>
		<a href="index2.php?option=com_myipn&task=config" title="Myipn Configuration">
                                <?php echo "Myipn Configuration"?></a>
		</td>
		<td>|<td>
		<td>
                <a href="index2.php?option=com_myipn&task=log" title="Sandbox and Transaction Error Log">
                                <?php echo "Sandbox and Transaction Error Log"?></a>
                </td>
		 <td>
                <a href="index2.php?option=com_myipn&task=deletefile" title="(Click to purge error log file)">
                                <?php echo " ( Purge error log )"?></a>
                </td>
		<td>|<td>
		<td>
                <a href="index2.php?option=com_myipn&task=about" title="About Myipn for Sobi 2">
                                <?php echo "About Myipn for Sobi 2"?></a>
                </td>
		</tr>
		</table>
		<table class="adminheading">
		<tr>
			<th nowrap="nowrap">
				Paypal Transaction listing
			</th>
		</tr>
		<tr>
			<td align="right">Username or Paypal Email Address:</td>
                        <td>
                        <input type="text" name="search" value="<?php echo $search;?>" class="text_area" /></td>
			<td align="right">
                        Transaction Status:
                        </td>
                        <td>
                        <select name="status">
                        <option value="<?php if(isset($_POST['status'])) echo $_POST['status'];?>" SELECTED><?php if(isset($_POST['status'])) echo $_POST['status'];?></option>
                        <option value="All">All</option>
                        <option value="Pending">Pending</option>
                        <option value="In-Progress">In-Progress</option>
                        <option value="Completed">Completed</option>
			<option value="Denied">Denied</option>
                        <option value="Refunded">Refunded</option>
                        </select>
                        </td>
			<td align="right"><input type="submit" name="submitbutton" value="Submit" class="button"></td>
		</tr>
		</table>

		<table class="adminlist">
		<tr>
			<th width="5">
			#
			</th>
			<th width="5">
			<input type="checkbox" name="toggle" value="" onClick="checkAll(<?php echo count( $rows ); ?>);" />
			</th>
			<th class="title">
			Username
			</th>
			<th align="left">
			Paypal Email
			</th>
			<th align="left">
                        Amount
                        </th>
			<th align="left">
                        Currency
                        </th>
			<th align="left">
			Sobi Category ID
			</th>
			<th align="left">
                        Sobi Entry ID
                        </th>
			<th align="left">
                        Payment Date
                        </th>
			<th align="left">
                        Txn ID
                        </th>
			 <th align="left">
                        Txn Status
                        </th>
			 <th align="left">
                        Txn Mode
                        </th>
		  </tr>
		<?php
		$k = 0;
		for ($i=0, $n=count( $rows ); $i < $n; $i++) {
			$row = &$rows[$i];

			$entrylink 	= 'index2.php?option=com_sobi2&task=edit&sobi2Id='.$row->entry_number.'&hidemainmenu=1&returnTask=listing&catid='.$row->entry_cat;
			$catlink  = 'index2.php?option=com_sobi2&task=listing&catid='.$row->entry_cat;
			
			$username = $row->username;
			
			$query = "SELECT * FROM #__users WHERE username='$username'";
			
			$database->setQuery($query);
			
			$rows1 =null;
			
			if($database->loadObject($rows1))
			
			$link2 	= 'index2.php?option=com_users&task=editA&id='.$rows1->id.'&hidemainmenu=1';
			?>
			<tr class="<?php echo "row$k"; ?>">
				<td>
				<?php echo $pageNav->rowNumber( $i ); ?>
				</td>
				<td align="center">
				<input type="checkbox" id="cb<?php echo $i;?>" name="cid[]" value="<?php echo $row->id; ?>" onClick="isChecked(this.checked);" />
				</td>
				<td align="left">
                                <a href="<?php echo $link2; ?>" title="Edit user">
                                <?php echo $row->username; ?>
                                </a>
                                </td>
				<td>
				<?php  echo htmlspecialchars($row->payer_email, ENT_QUOTES) 	?>
				<td align="left">
				<?php echo $row->payment_amount; ?>
				</td>
				<td align="left">
                                <?php echo $row->payment_currency; ?>
                                </td>
				<td align="left">
				<a href="<?php echo $catlink; ?>" title="View Category">
                                <?php echo "View Sobi Category"?></a>
                                </td>
				<td align="left">
				<a href="<?php echo $entrylink; ?>" title="Edit Entry">
                                <?php echo "View Sobi Entry"; ?></a>
                                </td>
				<td align="left">
                                <?php echo $row->payment_date; ?>
                                </td>
				<td align="left">
                                <?php echo $row->txn_id; ?>
                                </td>
				<td align="left">
                                <?php echo $row->payment_status; ?>
                                </td>
				<td align="left">
                                <?php if($row->test_ipn == '1') echo "Sandbox"; else echo "Paypal"; ?>
                                </td>

			</tr>
			<?php
			$k = 1 - $k;
		}
		?>
		</table>

		<?php echo $pageNav->getListFooter(); ?>

		<input type="hidden" name="option" value="com_myipn" />
		<input type="hidden" name="task" value="" />
		<input type="hidden" name="boxchecked" value="0" />
		<input type="hidden" name="hidemainmenu" value="0" />
		</form>
		<?php
	}


	function editConfig( $row ) {
		//echo "<pre>"; print_r ($row); echo "</pre>";
?>
<script language="javascript" type="text/javascript">
	function submitbutton(pressbutton) {
		var form = document.adminForm;
		if (pressbutton == 'cancel') {
			submitform( pressbutton );
			return;
		}

			submitform( pressbutton );
	}
</script>
	<div id="overDiv" style="position:absolute; visibility:hidden; z-index:10000;"></div>
	<table class="adminheading">
		<tr>
			<th class="edit">Myipn Configuration</th>
		</tr>
	</table>
	<form action="index2.php" method="post" name="adminForm">
	<table cellpadding="4" cellspacing="1" border="0" width="100%" class="adminform">
		<tr>
			<td>Sandbox:</td>
			<td><?php  echo $row->sandbox; ?></td>
			<td align="left">Use Sandbox testing mode or not</td>
		</tr>
  </table>
  <input type="hidden" name="id" value="1" />
  <input type="hidden" name="option" value="com_myipn" />
  <input type="hidden" name="task" value="" />
</form>
<script language="Javascript" src="../includes/js/overlib_mini.js"></script>
<?php }

	function showInfo($file) { ?>
		<table class="adminform">
		<tr>
		  <td>
		  	<pre><?php include ($file); ?></pre>
		  </td>
		</tr>
		</table>
		<?php
	}

	function deleteFile($file) {
		unlink($file);
		$ourFileHandle = fopen($file, 'w') or die("can't open file");
		fclose($ourFileHandle);
		$msg = 'Successfully purge error log file';
		mosRedirect( "index2.php?option=com_myipn&mosmsg=$msg" );

	}			
	function showAbout() {
	?>
	<table class="adminheading">
		<tr>
			<th>
				Myipn for Sobi 2 v1.0
			</th>
		</tr>
		<tr>
			<td>
				Myipn component for Sobi 2 v1.0<br />
				Copyright &copy; 2007 Ethan Chai Voon Chong, <a href="http://www.ethansoft.com" target="_blank">http://www.ethansoft.com</a><br />
				All Rights Reserved.<br />
				<br />
				This component is released under the terms of <a href="http://www.gnu.org/licenses/gpl.html" target="_blank">GNU General Public License</a>.<br />

				Support is given to whatever exists in Myipn Component. <br />
				If you wish to support the development and want more functionality like paypal transaction view, paypal transaction search with filtering,linking to sobi entry from the Paypal transaction view page and so on, then please consider purchase the component for 20.00 USD from my site: <a href="http://www.ethansoft.com">http://www.ethansoft.com</a>.<br />
				<br />
				To check for new versions or purchase of Myipn Component, please visit the project site:<br />
				<a href="http://www.ethansoft.com" target="_blank">http://www.ethansoft.com</a><br />
				<br />
				Thank you.
			</td>
		</tr>
	</table>

	<?php
	}

}

?>
